package com.dha.caodangcongnghe;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.dha.asynctask.DanhSachGiaoVienAsyncTask;
import com.dha.model.GiaoVienModel;
import com.dha.status.NetworkStatus;
import com.dha.ultility.QuangCao;

public class LayDanhSachGiaoVien extends ActionBarActivity {
	public static ArrayList<GiaoVienModel> arr;
	public static ListView lvDanhSachGiaoVien;
	public static ArrayAdapter<GiaoVienModel> adapter;
	private NetworkStatus networkStatus;
	
//	private QuangCao quangCao;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.danh_sach_giao_vien);
		
//		quangCao = new QuangCao(this, LayDanhSachGiaoVien.this);
		
		arr = new ArrayList<GiaoVienModel>();
		adapter = new ArrayAdapter<GiaoVienModel>(getBaseContext(),
				android.R.layout.simple_list_item_1, arr);
		lvDanhSachGiaoVien = (ListView) findViewById(R.id.lv_DanhSachGiaoVien);
		lvDanhSachGiaoVien.setAdapter(adapter);
		networkStatus = new NetworkStatus(getBaseContext());
		
		if (networkStatus.isConnected()) {
			DanhSachGiaoVienAsyncTask asyncTask = new DanhSachGiaoVienAsyncTask(
					LayDanhSachGiaoVien.this, arr, adapter);
			asyncTask.execute();
		} else {
			Intent intentLoi = new Intent("SuCoVeKetNoiMang");
			startActivity(intentLoi);
		}

		// thiet lap khi nhan lau vao 1 giao vien
		lvDanhSachGiaoVien.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (networkStatus.isConnected()) {
					Intent intent = new Intent("ThongBao");
					intent.putExtra("MaGiaoVien", arr.get(arg2).getMaGiaoVien()
							.toString());
					startActivity(intent);

					finish();
				} else {
					Intent intentLoi = new Intent("SuCoVeKetNoiMang");
					startActivity(intentLoi);
				}

			}
		});
	}

}
